package com.Controller.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sql.DAO;

import com.Model.Date.DateTime;
import com.Model.Pojo.Users;

public class KuaiJieXiaoFei extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html");
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();

		String type = request.getParameter("type");
    	
		int zhuanmoney = 0;
		String source;
		String style;
		int value = 0;
    	if(type.equals("f1")){
    		zhuanmoney = 100;
    		source = "快速赚钱";
    		value = 100;
    		style = "收入";
    	}else{
    		zhuanmoney = -200;
    		source = "快速花钱";
    		value = 200;
    		style = "消费";
    	}
		
    	Users usermoney = new Users();
		HttpSession session = request.getSession();
		usermoney = (Users)session.getAttribute("users");
		
		int money = usermoney.getYue();
		int cash = usermoney.getMoney();
		cash += zhuanmoney;
		DAO dao = new DAO();
		String usersname = usermoney.getZhanghao();
		String sql = "update users set yue='" + money + "' where name='" + usersname + "' ";
		dao.xiugai(sql);
		sql = "update users set money='" + cash + "' where name='" + usersname + "' ";
		dao.xiugai(sql);
		
		usermoney.setYue(money);
		usermoney.setMoney(cash);
		session.setAttribute("users", usermoney);
		
		DateTime date = new DateTime();
		sql = "insert into moneylist (name,style,value,date,cash,source)value('" + usersname + "','" + style
						+ "','" + value + "','" + date.getSettime() + "','" + cash + "','" + source + "')";
		dao.zengjia(sql);
		
		response.sendRedirect("/Bank/WebPage/FrontPage/FinancialServicePage/DepositAndWithdrawal.jsp");
	}
}
